package com.dx.architectureddd.app.executor;

import cn.hutool.core.bean.BeanUtil;
import com.dx.architectureddd.api.dto.req.FinishCmd;
import com.dx.architectureddd.domain.FlowNodeContext;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 执行器
 *
 * @author xin.deng
 * @date 2023/09/24
 */
@Slf4j
@Component
public class FinishCmdExe {
    @Resource
    private FlowExecutor flowExecutor;

    @Async
    public FlowNodeContext execute(FinishCmd finishCmd) {
        FlowNodeContext flowNodeContext = new FlowNodeContext();
        BeanUtil.copyProperties(finishCmd, flowNodeContext);
        LiteflowResponse liteflowResponse = flowExecutor.execute2Resp("finishExeChain", null, flowNodeContext);
        if (!liteflowResponse.isSuccess()) {
            // do something
            log.error("规则引擎执行出错");
            return flowNodeContext;
        }
        return flowNodeContext;
    }
}
